package com.kevin.websocket.client.configuration.websocket;

import com.kevin.websocket.client.configuration.websocket.properties.WebsocketProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import java.net.URI;
import java.net.URISyntaxException;

@Configuration
public class WebSocketClientConfiguration {

    @Bean
    @DependsOn("properties")
    public WebSocketClient client() throws URISyntaxException {
        WebSocketClient webSocketClient = new WebSocketClient(new URI(properties().getServerEndpoint() + "/" + properties().getId()));
        webSocketClient.connect();
        return webSocketClient;
    }

    @Bean
    public WebsocketProperties properties() {
        return new WebsocketProperties();
    }

}
